const connection = require('../app/database.js')
// 所有和数据库相关的操作
class labelServer {

  // 新增标签
  async create(name){
    // 1. 获取动态内容 拼接 statement
    const statement = 'INSERT INTO `label` (name) VALUES (?);'
    // 2. 执行sql语句 异步的操作
    const [result] = await connection.execute(statement, [name])
    return result
  }

  // 标签列表
  async selectList(offset = 0 , size = 10){
    // 1. 获取动态内容 拼接 statement
    const statement = 'SELECT * FROM label  LIMIT ? OFFSET ?'
    // 2. 执行sql语句 异步的操作
    const [result] = await connection.execute(statement, [size , offset])
    return result
  }


  // 查询label表中是否有同样的name
  async queryLabelByName (name){
    const statement = 'SELECT * FROM label WHERE name = ?;'
    const [result] = await connection.execute(statement , [name])
    return result[0]
  }



}
module.exports = new labelServer()